import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

import Layout from '@/layout'

// 引入多个动态路由模块
import approvalsRouter from './modules/approvals'
import departmentsRouter from './modules/departments'
import employeesRouter from './modules/employees'
import permissionRouter from './modules/permission'
import attendancesRouter from './modules/attendances'
import salarysRouter from './modules/salarys'
import settingRouter from './modules/setting'
import socialRouter from './modules/social'

// 动态路由规则数组
// 登录用户,身份不同,看见的路由页面不同->拥有的路由规则对象数量不同
// 例如:1300000002,超级管理员角色身份,看到8个所有页面
// 例如:1390000020,财务i总监角色身份,看到(员工/工资)2个页面->左侧导航有2个->路由规则对象
export const asyncRoutes = [
  approvalsRouter,
  departmentsRouter,
  employeesRouter,
  permissionRouter,
  attendancesRouter,
  salarysRouter,
  settingRouter,
  socialRouter
]

// 固定不变->静态路由规则数组

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout, // 登陆后跳转的布局页面
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'), // 懒加载
      meta: { title: '首页', icon: 'dashboard' }
    }
    ]
  },
  {
    path: '/excel',
    component: Layout,
    hidden: true,
    children: [{
      path: '',
      component: () => import('@/views/excel')
    }]
  },

  { path: '*', redirect: '/404', hidden: true }
]

// 由于员工岗位的不同,所能看到的页面不同
const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...asyncRoutes] // 将动,静路由规则对象合到一个数组里
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
